// banner-swiper.js
document.addEventListener('DOMContentLoaded', function() {
	// 主banner轮播配置
	const bannerSwiper = new Swiper('.banner.swiper-container', {
		loop: true,
		autoplay: {
			delay: 3000,
			disableOnInteraction: false,
		},
		pagination: {
			el: '.banner .swiper-pagination',
			clickable: true,
			bulletClass: 'swiper-pagination-bullet',
			bulletActiveClass: 'swiper-pagination-bullet-active-orange'
		},
		resistanceRatio: 0.6,
		touchAngle: 45,
		grabCursor: true,
	});

	// 解决方案轮播配置
	const solutionSwiper = new Swiper('.solution-swiper', {
		slidesPerView: 1,
		spaceBetween: 10,
		loop: true,
		pagination: {
			el: '.solution-swiper .swiper-pagination',
			clickable: true,
			bulletClass: 'swiper-pagination-bullet',
			bulletActiveClass: 'swiper-pagination-bullet-active-orange'
		},
		autoplay: {
			delay: 3000,
			disableOnInteraction: false,
		},
		breakpoints: {
			768: {
				slidesPerView: 2,
			}
		}
	});

	// 添加自定义样式
	const style = document.createElement('style');
	style.textContent = `
	
        .swiper-pagination-bullet-active-orange {
            background-color: #EB611E !important;
		
        }
    `;
	document.head.appendChild(style);
});
// 我们的产品
document.addEventListener('DOMContentLoaded', function() {
	new Swiper('.features-carousel', {
		slidesPerView: 1, // 每次只显示1个
		spaceBetween: 20,
		loop: true, // 循环模式
		pagination: {
			el: '.swiper-pagination-features',
			clickable: true,
		},
		autoplay: {
			delay: 3000, // 3秒自动切换
			disableOnInteraction: false,
		},
		grabCursor: true, // 显示抓手光标
	});
})

// 我们的产品轮播图2

let currentIndex = 0;
const itemsPerView = 3; // 同时显示3个
const totalItems = document.querySelectorAll('.carousel-item').length;

function moveCarousel() {
	const carousel = document.querySelector('.carousel');

	// 每次移动一个项目（33.33%宽度）
	currentIndex = (currentIndex + 1) % (totalItems - itemsPerView + 1);

	// 如果到达末尾，回到开头（无缝循环）
	if (currentIndex === totalItems - itemsPerView + 1) {
		setTimeout(() => {
			carousel.style.transition = 'none';
			carousel.style.transform = 'translateX(0)';
			currentIndex = 0;
			// 强制重绘
			setTimeout(() => {
				carousel.style.transition = 'transform 0.5s ease-in-out';
			}, 10);
		}, 500);
	}

	carousel.style.transform = `translateX(-${currentIndex * 33.33}%)`;
}

setInterval(moveCarousel, 3000); // 每3秒移动一个

// 克隆前3个项目并添加到末尾，实现无缝循环
// document.addEventListener('DOMContentLoaded', function() {
// 	const carousel = document.querySelector('.carousel');
// 	const items = document.querySelectorAll('.carousel-item');

// 	for (let i = 0; i < itemsPerView; i++) {
// 		const clone = items[i].cloneNode(true);
// 		carousel.appendChild(clone);
// 	}
// });
// 科研中心


// 最新消息
document.addEventListener('DOMContentLoaded', function() {
	const wrapper = document.querySelector('.news-carousel-wrapper');
	const slides = document.querySelectorAll('.news-carousel-slide');
	let currentIndex = 0;

	// 克隆第一张幻灯片并添加到末尾
	const firstSlide = slides[0].cloneNode(true);
	wrapper.appendChild(firstSlide);

	// 设置容器宽度
	// wrapper.style.width = `${slides.length + 1}00%`;

	// 自动轮播
	setInterval(() => {
		currentIndex++;
		const translateX = -currentIndex * 100;

		// 添加滑动动画
		wrapper.style.transition = 'transform 0.5s ease';
		wrapper.style.transform = `translateX(${translateX}%)`;

		// 如果是克隆的幻灯片，无动画回到第一张
		if (currentIndex === slides.length) {
			setTimeout(() => {
				wrapper.style.transition = 'none';
				currentIndex = 0;
				wrapper.style.transform = 'translateX(0)';
			}, 500);
		}
	}, 3000); // 3秒切换一次
});

//建筑领域选择卡片
document.querySelectorAll('.card-item').forEach(item => {
	item.addEventListener('click', function(e) {
		e.preventDefault(); // 阻止链接跳转

		// 移除所有active类
		document.querySelectorAll('.card-item').forEach(i => {
			i.classList.remove('active');
		});

		// 给当前点击项添加active
		this.classList.add('active');
	});
});
// 相关产品按钮
document.addEventListener('DOMContentLoaded', function() {
	const modules = document.querySelectorAll('.module');
	modules.forEach(function(module) {
		const relatedProducts = module.querySelector('.related-products');
		const ourProducts = module.querySelector('.OurProducts');

		relatedProducts.addEventListener('click', function() {
			const currentHeight = ourProducts.style.maxHeight;
			if (currentHeight === '0px') {
				ourProducts.style.maxHeight = ourProducts.scrollHeight + 'px';
				relatedProducts.classList.add('active');
			} else {
				ourProducts.style.maxHeight = '0px';
				relatedProducts.classList.remove('active');
			}
		});
	});
});
// 创新与制造选择卡片
// const createBox = document.getElementById('create-box');
// const makeBox = document.getElementById('make-box');

// // 页面加载完成后默认选中第一个
// window.onload = function() {
// 	createBox.classList.add('selected');
// };

// createBox.addEventListener('click', function() {
// 	createBox.classList.add('selected');
// 	makeBox.classList.remove('selected');
// });

// makeBox.addEventListener('click', function() {
// 	makeBox.classList.add('selected');
// 	createBox.classList.remove('selected');
// });




// 产品详情图片切换